package java8.myStream;

import java.util.Arrays;
import java.util.IntSummaryStatistics;
import java.util.List;
import java.util.stream.Collector;
import java.util.stream.Collectors;

/**
 * 功能描述:集成实体数据 teeing  teeing0
 *  jdk 12 后才出现
 * 2024/08/26
 *
 * @author ZhangYi
 */
public class IntegrateEntityData {
	public static void main(String[] args) {
		List<Person> people = Arrays.asList(
				new Person("Alice", 20),
				new Person("Bob", 17),
				new Person("Charlie", 22),
				new Person("Diana", 19),
				new Person("Eve", 25),
				new Person("Frank", 16)
		);
//		// 使用 teeing 方法进行复合收集
//		Collector<Person, ?, PersonSummary> collector = Collectors.teeing(
//				Collectors.mapping(Person::getName, Collectors.toList()),
//				Collectors.summarizingInt(Person::getAge),
//				(names, ageStats) -> new PersonSummary(names, ageStats)
//		);
//
//		PersonSummary summary = people.stream().collect(collector);
//
//		System.out.println("Summary: " + summary);

//		// 使用 teeing0 方法进行复合收集
//		Collector<Person, ?, PersonSummary> collector = teeing0(
//				Collectors.mapping(Person::getName, Collectors.toList()),
//				Collectors.summarizingInt(Person::getAge),
//				(names, ageStats) -> new PersonSummary(names, ageStats)
//		);
//
//		PersonSummary summary = people.stream().collect(collector);
//
//		System.out.println("Summary: " + summary);
	}

}
class PersonSummary {
	private List<String> names;
	private IntSummaryStatistics ageStats;

	public PersonSummary(List<String> names, IntSummaryStatistics ageStats) {
		this.names = names;
		this.ageStats = ageStats;
	}

	public List<String> getNames() {
		return names;
	}

	public IntSummaryStatistics getAgeStats() {
		return ageStats;
	}

	@Override
	public String toString() {
		return "PersonSummary{" +
				"names=" + names +
				", ageStats=" + ageStats +
				'}';
	}
}
